var t = getApp();

Page({
    data: {
        inputs: "",
        pageNum: 1,
        goods: [],
        goload: !1,
        styleObj: {
            display: "inline-block",
            marginRight: "25px",
            backgroundColor: "white",
            marginLeft: "5px",
            position: "static"
        },
        jumpSo: !0,
        store_id: "",
        loading: !1,
        allLoaded: !0,
        classifyBol: !0,
        showHistory: !1
    },
    onLoad: function(t) {
        t.store_id && this.setData({
            store_id: t.store_id
        }), t.goods_ids ? this.getIds(t.goods_ids) : this.gotoSearch();
    },
    serachTag: function(t) {
        var a = t.detail;
        this.setData({
            inputs: a
        });
    },
    onReady: function() {},
    getIds: function(a) {
        var o = this, s = t.getNetAddresss("plugin.store-cashier.frontend.store.goods.get-goods-by-ids");
        s += "&store_id=" + this.data.store_id, s += "&goods_ids=" + a, this.options.cid && (s += "&category_id=" + this.options.cid), 
        t._getNetWork({
            url: s,
            success: function(t) {
                var a = t.data;
                if (1 == a.result) {
                    if (o.setData({
                        pageNum: Number(o.data.pageNum) + 1,
                        loading: !1,
                        allLoaded: !1
                    }), o.setData({
                        goods: a.data.data
                    }), a.data.current_page == a.data.last_page || a.data.total <= 0) return void o.setData({
                        loading: !0,
                        allLoaded: !0
                    });
                } else o.setData({
                    loading: !0,
                    allLoaded: !0
                });
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {
        this.gotoSearch();
    },
    onShareAppMessage: function() {},
    inpbtn: function(t) {
        var a = t.detail.value;
        this.setData({
            inputs: a
        });
    },
    inpFocus: function(t) {
        this.setData({
            showHistory: !0
        });
    },
    inpBlur: function(t) {
        var a = t.detail.value;
        this.setData({
            inputs: a,
            showHistory: !1
        });
    },
    search: function() {
        this.setData({
            pageNum: 1,
            goods: [],
            goload: !0
        }), this.gotoSearch();
    },
    gotoSearch: function() {
        this.data.inputs && this.selectComponent("#search_history").appendKeywords(this.data.inputs);
        var a = this, o = t.getNetAddresss("plugin.store-cashier.frontend.store.goods.get-goods-by-kwd");
        o += "&store_id=" + this.data.store_id, o += "&kwd=" + this.data.inputs, o += "&page=" + this.data.pageNum, 
        this.options.cid && (o += "&category=" + this.options.cid), t._getNetWork({
            url: o,
            success: function(t) {
                var o = t.data;
                if (1 == o.result) {
                    a.setData({
                        pageNum: Number(a.data.pageNum) + 1,
                        loading: !1,
                        allLoaded: !1
                    });
                    var s = a.data.goods;
                    if (a.setData({
                        goods: s.concat(o.data.data)
                    }), o.data.current_page == o.data.last_page || o.data.total <= 0) return void a.setData({
                        loading: !0,
                        allLoaded: !0
                    });
                } else a.setData({
                    loading: !0,
                    allLoaded: !0
                });
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    classifyShowBtn: function() {
        this.data.classifyBol ? this.setData({
            classifyBol: !1
        }) : this.setData({
            classifyBol: !0
        });
    }
});